#pragma once

#include "Chart.h"
#include "Timing.h"

namespace LSCM
{
	/**
	 * @file ChartBuilder.h
	 * @author xingyifan
	 * @date 2023-08-17 14:41
	 * 
	 * @description: 图表构建器
	 */
	
	class ChartBuilder
	{
	private:
		// 保存网格和特征集
		Mesh* m_mesh;
		const std::vector<LSCM::FeatureSet>& m_featureSets;

		// 记录最大距离
		float m_maxDistance;

		// 保存图表
		std::vector<Chart> m_charts;

		// 用来增加边和面的属性
		OpenMesh::EPropHandleT<int> m_chartBoundaries;
		OpenMesh::FPropHandleT<FaceState> m_faceStates;

	public:
		ChartBuilder(Mesh* mesh, const std::vector<LSCM::FeatureSet>& sets);
		~ChartBuilder();

		const std::vector<Chart>& Build();
		bool Validate();

	private:
		void initializeDistance();	// 初始化每个面到每个特征集的距离
		void initializeSeeds();		// 初始化图表种子
		void buildCharts();			// 构建图表

		bool removeChartBoundaryEdge(Mesh::EdgeHandle edge);
		bool checkChartBoundaryEdge(Mesh::EdgeHandle edge);
		void mergeCharts(Chart& chartTo, Chart& chartFrom);
	};
}